import { Component, OnInit } from '@angular/core';
import { Recharge } from '../../interfaces/recharge.interfaces';
import { ModalService, Pagination } from 'ng-tui';
import { JoblService } from '../../services/job.service';
import { GlobalService, AuthService } from '../../../../cores/services';
import { HttpConfig } from '../../../../configs/http.config';
import { ApiData, SearchParams } from '../../../../cores/classes';

@Component({
    template: `
    <div class="modal-content">
    <div class="modal-header">
        <h5 class="modal-title">添加职位</h5>
        <button (click)="modal.dismiss()" type="button" class="close">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div style="border-top: 3px solid #387ddd !important;width: 75px;margin-left: 20px;"></div>
    <div class="modal-body">
        <div class="form-group row" *ngIf="userInfo.roleId!=1">
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">选择部门</label>
            <div class="col-sm-10">
                <select class="form-control pr-int" [(ngModel)]="banner.departmentId" (change)="getPosition(banner.departmentId)">
                    <option value="" style="color: #b6b6b6" disabled selected selected="selected">请选择部门</option>
                    <option *ngFor="let item of getlista" [ngValue]="item.id">{{item.departmentName}}</option>
                </select>
            </div>
        </div>

        <div class="form-group row">
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">职位名称</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" [(ngModel)]="banner.positionName" placeholder="请输入职位名称关键词">
            </div>
        </div>
    </div>
    <div class="modal-footer" style="justify-content: center; ">
        <button (click)="modal.dismiss()" type="button" class="btn" style="background-color: #eaf4ff;
    border-color: #dae0e5;color: #000;width: 18%;margin-right: 1.25rem;">取消</button>
        <button tsBtn loading (submit)="confirmSave($event)" style="background-color: #387ddd;width: 18%;
    border-color: #387ddd;" color="success">保存</button>
    </div>
</div>`,
})
export class ModalComponent {
    getlist = new Array<any>();
    getlista = new Array<any>();
    conpay = new Array<any>();
    pagination = new Pagination();
    search = new SearchParams({ status: '', uid: '', orderSn: '' });

    loading = false;
    selectValue = 1;
    uploading = false;
    userInfo: any;
    banner: Recharge = {};
    listShoper = new Array<any>();

    constructor(
        public global: GlobalService,
        public modal: ModalService,
        private joblService: JoblService,
        private auth: AuthService,
    ) {

        this.departmentLista();
    }
    /**
     * 职位增删
     * @param btn
     */
    confirmSave(btn: any) {
        (this.banner.id > 0 ? this.joblService.updateBanner(this.banner) : this.joblService.insertBanner(this.banner))
            .subscribe({
                next: () => this.modal.close(),
                complete: () => btn.dismiss()
            });
    }
    /**
     * 部门列表
     */
    departmentLista() {
        this.userInfo = this.auth.user;
        this.joblService.joblist(this.pagination, this.search)
            .subscribe({
                next: res => {
                    this.pagination.total = res.datas.total;
                    this.getlista = res.datas;
                },
                complete: () => this.loading = false
            });
    }

}
